package com.ruoyi.web.controller.warn;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warn.domain.BusWaterWarnrule;
import com.ruoyi.warn.service.IBusWaterWarnruleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预警规则Controller
 * 
 * @author maliang
 * @date 2025-09-10
 */
@RestController
@RequestMapping("/warn/warnrule")
public class BusWaterWarnruleController extends BaseController
{
    @Autowired
    private IBusWaterWarnruleService busWaterWarnruleService;

    /**
     * 查询预警规则列表
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrule:list')")
    @GetMapping("/list")
    public AjaxResult list(BusWaterWarnrule busWaterWarnrule)
    {
        List<BusWaterWarnrule> list = busWaterWarnruleService.selectBusWaterWarnruleList(busWaterWarnrule);
        return AjaxResult.success(list);
    }

    /**
     * 导出预警规则列表
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrule:export')")
    @Log(title = "预警规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusWaterWarnrule busWaterWarnrule)
    {
        List<BusWaterWarnrule> list = busWaterWarnruleService.selectBusWaterWarnruleList(busWaterWarnrule);
        ExcelUtil<BusWaterWarnrule> util = new ExcelUtil<BusWaterWarnrule>(BusWaterWarnrule.class);
        util.exportExcel(response, list, "预警规则数据");
    }

    /**
     * 获取预警规则详细信息
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(busWaterWarnruleService.selectBusWaterWarnruleById(id));
    }

    /**
     * 新增预警规则
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrule:add')")
    @Log(title = "预警规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusWaterWarnrule busWaterWarnrule)
    {
        return toAjax(busWaterWarnruleService.insertBusWaterWarnrule(busWaterWarnrule));
    }

    /**
     * 修改预警规则
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrule:edit')")
    @Log(title = "预警规则", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BusWaterWarnrule busWaterWarnrule)
    {
        return toAjax(busWaterWarnruleService.updateBusWaterWarnrule(busWaterWarnrule));
    }

    /**
     * 删除预警规则
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrule:remove')")
    @Log(title = "预警规则", businessType = BusinessType.DELETE)
	@PostMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(busWaterWarnruleService.deleteBusWaterWarnruleByIds(ids));
    }
}
